dofile ("libColor.lua")
dofile ("StylusBox.lua")

CheckBox = {}

function CheckBox.draw (chmax, text1, text2, text3, text4)
  screen.drawFillRect (SCREEN_DOWN, 0, 0, 256, 192, Color.mod (240, 240, 240))
  casex1 = 47
  casey1 = 50
  casex2 = 55
  casey2 = 58
  stxwx = 60
  stxwy = 50
  if chmax==2 then
    screen.print (SCREEN_DOWN, stxwx, stxwy, text1, Color.new (0, 0, 0))
    screen.drawRect (SCREEN_DOWN, casex1, casey1, casex2, casey2, Color.new (31, 31, 31))
    screen.drawRect (SCREEN_DOWN, casex1, casey1, casex2, casey2, Color.new (0, 0, 0))
    screen.print (SCREEN_DOWN, stxwx, stxwy+11, text2, Color.new (0, 0, 0))
    screen.drawRect (SCREEN_DOWN, casex1, casey1+11, casex2, casey2+11, Color.new (31, 31, 31))
    screen.drawRect (SCREEN_DOWN, casex1, casey1+11, casex2, casey2+11, Color.new (0, 0, 0))
    bx1 = newBox (casex1, casey1, 256, casey2)
    bx2 = newBox (casex1, casey1+11, 256, casey2+11)
    if Stylus.newPressinBox (bx1, x, y) then
      choix = 1
    elseif Stylus.newPressinBox (bx2, x, y) then
      choix = 2
    end
    if choix==1 then
      screen.drawFillRect (SCREEN_DOWN, casex1, casey1, casex2, casey2, Color.new (0, 0, 0))
    elseif choix==2 then
      screen.drawFillRect (SCREEN_DOWN, casex1, casey1+11, casex2, casey2+11, Color.new (0, 0, 0))
    end
  elseif chmax==3 then  
    screen.print (SCREEN_DOWN, stxwx, stxwy, text1, Color.new (0, 0, 0))
    screen.drawRect (SCREEN_DOWN, casex1, casey1, casex2, casey2, Color.new (31, 31, 31))
    screen.drawRect (SCREEN_DOWN, casex1, casey1, casex2, casey2, Color.new (0, 0, 0))
    screen.print (SCREEN_DOWN, stxwx, stxwy+11, text2, Color.new (0, 0, 0))
    screen.drawRect (SCREEN_DOWN, casex1, casey1+11, casex2, casey2+11, Color.new (31, 31, 31))
    screen.drawRect (SCREEN_DOWN, casex1, casey1+11, casex2, casey2+11, Color.new (0, 0, 0))
    screen.print (SCREEN_DOWN, stxwx, stxwy+21, text3, Color.new (0, 0, 0))
    screen.drawRect (SCREEN_DOWN, casex1, casey1+21, casex2, casey2+21, Color.new (31, 31, 31))
    screen.drawRect (SCREEN_DOWN, casex1, casey1+21, casex2, casey2+21, Color.new (0, 0, 0))
    bx1 = newBox (casex1, casey1, 256, casey2)
    bx2 = newBox (casex1, casey1+11, 256, casey2+11)
    bx3 = newBox (casex1, casey1+21, 256, casey2+21)
    if Stylus.newPressinBox (bx1, x, y) then
      choix = 1
    elseif Stylus.newPressinBox (bx2, x, y) then
      choix = 2
    elseif Stylus.newPressinBox (bx3, x, y) then
      choix = 3
    end
    if choix==1 then
      screen.drawFillRect (SCREEN_DOWN, casex1, casey1, casex2, casey2, Color.new (0, 0, 0))
    elseif choix==2 then
      screen.drawFillRect (SCREEN_DOWN, casex1, casey1+11, casex2, casey2+11, Color.new (0, 0, 0))
    elseif choix==3 then
      screen.drawFillRect (SCREEN_DOWN, casex1, casey1+21, casex2, casey2+21, Color.new (0, 0, 0))
    end
  elseif chmax==4 then
    screen.print (SCREEN_DOWN, stxwx, stxwy, text1, Color.new (0, 0, 0))
    screen.drawRect (SCREEN_DOWN, casex1, casey1, casex2, casey2, Color.new (31, 31, 31))
    screen.drawRect (SCREEN_DOWN, casex1, casey1, casex2, casey2, Color.new (0, 0, 0))
    screen.print (SCREEN_DOWN, stxwx, stxwy+11, text2, Color.new (0, 0, 0))
    screen.drawRect (SCREEN_DOWN, casex1, casey1+11, casex2, casey2+11, Color.new (31, 31, 31))
    screen.drawRect (SCREEN_DOWN, casex1, casey1+11, casex2, casey2+11, Color.new (0, 0, 0))
    screen.print (SCREEN_DOWN, stxwx, stxwy+21, text3, Color.new (0, 0, 0))
    screen.drawRect (SCREEN_DOWN, casex1, casey1+21, casex2, casey2+21, Color.new (31, 31, 31))
    screen.drawRect (SCREEN_DOWN, casex1, casey1+21, casex2, casey2+21, Color.new (0, 0, 0))
    screen.print (SCREEN_DOWN, stxwx, stxwy+31, text4, Color.new (0, 0, 0))
    screen.drawRect (SCREEN_DOWN, casex1, casey1+31, casex2, casey2+31, Color.new (31, 31, 31))
    screen.drawRect (SCREEN_DOWN, casex1, casey1+31, casex2, casey2+31, Color.new (0, 0, 0))
    bx1 = newBox (casex1, casey1, 256, casey2)
    bx2 = newBox (casex1, casey1+11, 256, casey2+11)
    bx3 = newBox (casex1, casey1+21, 256, casey2+21)
    bx4 = newBox (casex1, casey1+31, 256, casey2+31)
    if Stylus.newPressinBox (bx1, x, y) then
      choix = 1
    elseif Stylus.newPressinBox (bx2, x, y) then
      choix = 2
    elseif Stylus.newPressinBox (bx3, x, y) then
      choix = 3
    elseif Stylus.newPressinBox (bx4, x, y) then
      choix = 4
    end
    if choix==1 then
      screen.drawFillRect (SCREEN_DOWN, casex1, casey1, casex2, casey2, Color.new (0, 0, 0))
    elseif choix==2 then
      screen.drawFillRect (SCREEN_DOWN, casex1, casey1+11, casex2, casey2+11, Color.new (0, 0, 0))
    elseif choix==3 then
      screen.drawFillRect (SCREEN_DOWN, casex1, casey1+21, casex2, casey2+21, Color.new (0, 0, 0))
    elseif choix==4 then
      screen.drawFillRect (SCREEN_DOWN, casex1, casey1+31, casex2, casey2+31, Color.new (0, 0, 0))
    end
  else 
    chmax = 4
  end
  screen.drawFillRect (SCREEN_DOWN, 85, 127, 166, 158, c_grisclair)
  screen.print (SCREEN_DOWN, 95, 137, "OK", c_noir)
  ok = newBox (85, 127, 166, 158)
  if Stylus.newPressinBox (ok, x, y) and choix==1 then
    reponse = 1
  elseif Stylus.newPressinBox (ok, x, y) and choix==2 then
    reponse = 2
  elseif Stylus.newPressinBox (ok, x, y) and choix==3 then
    reponse = 3
  elseif Stylus.newPressinBox (ok, x, y) and choix==4 then
    reponse = 4
  end
end
